#include <stdio.h>
#include "gui_entry.h"
#include "gui_menu.h"
#include "sys_stdio.h"
#include "sys_time.h"
static GUI_OBJECT(menu);
static GUI_OBJECT(location);
static GUI_OBJECT(deviceid);
static GUI_OBJECT(desktop);
static GUI_OBJECT(time);

static int desktop_content(struct lcd_display_tools *tools)
{
    int ret =0;
    struct desktop_signal_value value;
    value.gps = 1;
    value.value_4g = 2;
    value.signal = 1;
    value.camera = 2;
    value.hard_disk = 0;
    value.sd_card = 1;
    struct sj_time sys_time={0};
    if(tools->display_pic != NULL)
    {
        tools->display_pic(0, 0, &value);
    }

    if(tools->display==NULL)
    {
        goto out;
    }

    char date[10] = "";
    char time[10] = "";
    get_localtime(&sys_time);

    sprintf(date, "%02d-%02d-%02d", sys_time.year, sys_time.month, sys_time.date);
    sprintf(time, "%02d:%02d:%02d", sys_time.hours, sys_time.minutes, sys_time.seconds);
    tools->display(0,4,time,0);
    tools->display(80,4,"80km/h",0);
    tools->display(0,6,date,0);
    char week[5] = "";
    switch(sys_time.week_day)
    {
        case 1:
            tools->display(70,6,"星期一",0);
            break;
        case 2:
            tools->display(70,6,"星期二",0);
            break;
        case 3:
            tools->display(70,6,"星期三",0);
            break;
        case 4:
            tools->display(70,6,"星期四",0);
            break;
        case 5:
            tools->display(70,6,"星期五",0);
            break;
        case 6:
            tools->display(70,6,"星期六",0);
            break;
        case 7:
            tools->display(70,6,"星期日",0);
            break;
    }
    //tools->display(70,6,"星期四",0);

//    sj_kprintf("时间 09:17:23  \r\n");
//    sj_kprintf("时速:80km/h \r\n");
//    sj_kprintf("21-11-17 \r\n");
//    sj_kprintf("星期四 \r\n");

    out:
    return ret;
}

static int location_content(struct lcd_display_tools *tools)
{
    int ret =0;
    if(tools->display==NULL)
    {
        goto out;
    }
    tools->display(0,0,"未定位",0);

    sj_kprintf("未定位 \r\n");
    out:
    return ret;
}

static int deviceid_content(struct lcd_display_tools *tools)
{
    int ret =0;
    if(tools->display==NULL)
    {
        goto out;
    }
    tools->display(0,0,"设备唯一码",0);
    tools->display(0,2,"080000511060",0);

    sj_kprintf("设备唯一码:080000511060 \r\n");
    out:
    return ret;
}

static int time_content(struct lcd_display_tools *tools)
{
    int ret =0;
    if(tools->display==NULL)
    {
        goto out;
    }
    tools->display(0,0,"驾驶时长(分钟):3",0);
    tools->display(0,2,"休息时长(分钟):4",0);

    sj_kprintf("驾驶时长(分钟):3 \r\n");
    sj_kprintf("休息时长(分钟):4 \r\n");

    out:
    return ret;
}

void gui_entry_get(struct gui_console *console)
{
    gui_object_init(&menu,"menu");
    gui_object_init(&location,"location");
    gui_object_init(&deviceid,"deviceid");
    gui_object_init(&desktop,"desktop");
    gui_object_init(&time,"time");

    gui_object_add_content(&desktop,desktop_content);
    gui_object_add_content(&location,location_content);
    gui_object_add_content(&deviceid,deviceid_content);
    gui_object_add_content(&time,time_content);

    gui_object_add_child(&location,&menu);
    gui_object_add_child(&deviceid,&menu);
    gui_object_add_child(&time,&menu);
    gui_object_add_child(&desktop,&menu);

    gui_menu_add_child(&menu);


    gui_object_add_peer(&time, &desktop);
    gui_object_add_peer(&location, &desktop);
    gui_object_add_peer(&deviceid, &desktop);

    console->current=&desktop;
    console->current_object_duration=11;
    console->current_input_type = BUTTON_NONE;
}

